/*
 * KeyEvent.h
 *
 *  Created on: 2010-9-9
 *      Author: wenjian
 */

#ifndef KEYEVENT_H_
#define KEYEVENT_H_

#include "ddatatypes.h"
#include "eventtypes.h"
#include <event/Event.h>
#include "KeySequence.h"

namespace Ed {

  class KeyEvent: public Thk::Event {
    public:
      KeyEvent(EventType type, int key, void* source=NULL);
      KeyEvent(EventType type, const KeySequence& ks, void* source=NULL);
      KeyEvent(EventType type, int key, const KeySequence& ks, void* source=NULL);
      virtual ~KeyEvent();

      /**
       * 测试键
       */
      bool test(int k) const{
        return k==key || keySequence.test(k);
      }

      int getKey() const{
        return key;
      }

      inline const KeySequence& getKeySequence() const{
        return keySequence;
      }

      /**
       * 检查是否键盘事件
       */
      static inline bool isKeyEvent(EventType type){
        return type==PressType || type==ReleaseType;
      }

      /**
       * 检查是否键盘事件
       */
      static inline bool isKeyEvent(const Event* e){
        EventType type = e->getType();
        return type==PressType || type==ReleaseType;
      }

      //所有键盘相关事件类型
      static EventType PressType;
      static EventType ReleaseType;

    protected:
      //当前操作键
      int key;
      //键序列
      KeySequence keySequence;

  };

}

#endif /* KEYEVENT_H_ */
